﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System.Xml;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;

namespace XeoEngine
{
    class SoundOptionsMenuScreen : MenuScreen
    {
        SliderMenuEntry mVol;
        SliderMenuEntry smVol;
        SliderMenuEntry sVol;

        public SoundOptionsMenuScreen()
            : base(Localizations.Strings.Sound)
        {

        }

        public override void LoadContent()
        {
            ContentManager content = new ContentManager(ScreenManager.Game.Services, "Content");
            MenuEntry apply = new MenuEntry(Localizations.Strings.Apply);
            mVol = new SliderMenuEntry(Localizations.Strings.mVol, content, (int)(ScreenManager.mvol*100));
            smVol = new SliderMenuEntry(Localizations.Strings.smVol, content, (int)(ScreenManager.smvol * 100));
            sVol = new SliderMenuEntry(Localizations.Strings.sVol, content, (int)(ScreenManager.svol * 100));
            apply.Selected += OnApply;
            mVol.Rolled += OnRoll;
            smVol.Rolled += OnRoll;
            sVol.Rolled += OnRoll;
            MenuEntries.Add(mVol);
            MenuEntries.Add(smVol);
            MenuEntries.Add(sVol);
            MenuEntries.Add(apply);
            base.LoadContent();
        }

        void OnRoll(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.audioEngine.GetCategory("Music").SetVolume(smVol.Value / 100.0f);
            ScreenManager.audioEngine.GetCategory("Menu").SetVolume(mVol.Value / 100.0f);
            ScreenManager.audioEngine.GetCategory("Scene").SetVolume(sVol.Value / 100.0f);
            ScreenManager.smvol = smVol.Value / 100.0f;
            ScreenManager.mvol = mVol.Value / 100.0f;
            ScreenManager.svol = sVol.Value / 100.0f;
        }

        void OnApply(object sender, PlayerIndexEventArgs e)
        {
            GraphicOptionsMenuScreen.SaveSettings(ScreenManager);
            OnCancel(PlayerIndex.One);
        }
    }
}
